//
//  VideoViewController.swift
//  ProjectApp
//
//  Created by 邹琳 on 2019/5/31.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit

class HomeViewController: BaseTableViewController {
    
    var searchView: UITextField = {
    	var temp = UITextField()
        temp.font = UIFont.systemFont(ofSize: 15)
        temp.textColor = UIColor.black
        temp.placeholder = "搜索昵称/唱聊ID/房间名"
        temp.backgroundColor = UIColor(0xf1f1f1)
        temp.layer.cornerRadius = 18
        temp.layer.masksToBounds = true
        temp.leftViewMode = UITextField.ViewMode.always
       	return temp
    }()
    let searchImageView: UIView = {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        let temp = UIImageView(image: UIImage(named: "search_icon")!)
        view.addSubview(temp)
        temp.snp.makeConstraints({ (make) in
            make.centerY.centerX.equalTo(view)
        })
        return view
    }()
    
    let homeHeaderView: HomeHeaderView = {
        let temp = HomeHeaderView.createFromNib()!
        return temp
    }()
    let homePeopleSection: HomePeopleMenueSection = {
        return HomePeopleMenueSection.createFromNib()!
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
		view.backgroundColor = UIColor.white
        
        self.searchView.leftView = self.searchImageView
        self.rightItem.setImage(UIImage(named: "house"), for: .normal)
        
        self.naviView.addSubview(self.searchView)
        self.searchView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.bottom.equalTo(-4)
            make.right.equalTo(-65)
            make.height.equalTo(36)
        }
        
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
    }
}

extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 0
        }
        return 3
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if section == 0 {
            return self.homeHeaderView
        }
        if section == 1 {
            return self.homePeopleSection
        }
        return nil
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 371
        }
        
        if section == 1 {
            return 73
        }
        
        return 0.0001
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = "\(indexPath.row)"
        return cell!
    }
}
